<?php
class RP_Model_User_Recruiter extends RP_Model_User_Base{
	
	private $recruiter_name;
	
	private $recruiter_type;
	
	private $contact_no;
	
	private $alternate_no;
	
	private $contact_person;
	
	private $industry_id;
	
	private $industry_name;
	
	private $addressline;
	
	private $city;
	
	private $district;
	
	private $state;
	
	private $pincode;
	
	private $mapper;

	/**
	 * Overridden function getUser_type_id();
	 * @return the $user_type_id 
	 */
	public function getUser_type_id() {
		if(!isset($this->_user_type_id)){
			$this->setUser_type_id('RCTR');
		}
		return $this->_user_type_id;
	}
	   	/**
	 * @return the $recruiter_name
	 */
	public function getRecruiter_name() {
		return $this->recruiter_name;
	}

	/**
	 * @return the $recruiter_type
	 */
	public function getRecruiter_type() {
		return $this->recruiter_type;
	}

	/**
	 * @return the $contact_no
	 */
	public function getContact_no() {
		return $this->contact_no;
	}

	/**
	 * @return the $alternate_no
	 */
	public function getAlternate_no() {
		return $this->alternate_no;
	}

	/**
	 * @return the $contact_person
	 */
	public function getContact_person() {
		return $this->contact_person;
	}

	/**
	 * @return the $industry_id
	 */
	public function getIndustry_id() {
		return $this->industry_id;
	}

	/**
	 * @return the $industry_name
	 */
	public function getIndustry_name() {
		return $this->industry_name;
	}

	/**
	 * @return the $addressline
	 */
	public function getAddressline() {
		return $this->addressline;
	}

	/**
	 * @return the $city
	 */
	public function getCity() {
		return $this->city;
	}

	/**
	 * @return the $district
	 */
	public function getDistrict() {
		return $this->district;
	}

	/**
	 * @return the $state
	 */
	public function getState() {
		return $this->state;
	}

	/**
	 * @return the $state
	 */
	public function getPincode() {
		return $this->pincode;
	}
	
	/**
	 * @return the $mapper
	 */
	public function getMapper()
    {
        if (null === $this->mapper) {
            $this->setMapper(new RP_Model_User_RecruiterMapper());
        }
        return $this->mapper;
    }

	/**
	 * @param field_type $recruiter_name
	 */
	public function setRecruiter_name($recruiter_name) {
		$this->recruiter_name = $recruiter_name;
		return $this;
	}

	/**
	 * @param field_type $recruiter_type
	 */
	public function setRecruiter_type($recruiter_type) {
		$this->recruiter_type = $recruiter_type;
		return $this;
	}

	/**
	 * @param field_type $contact_no
	 */
	public function setContact_no($contact_no) {
		$this->contact_no = $contact_no;
		return $this;
	}

	/**
	 * @param field_type $alternate_no
	 */
	public function setAlternate_no($alternate_no) {
		$this->alternate_no = $alternate_no;
		return $this;
	}

	/**
	 * @param field_type $contact_person
	 */
	public function setContact_person($contact_person) {
		$this->contact_person = $contact_person;
		return $this;
	}

	/**
	 * @param field_type $industry_id
	 */
	public function setIndustry_id($industry_id) {
		$this->industry_id = $industry_id;
		return $this;
	}

	/**
	 * @param field_type $industry_name
	 */
	public function setIndustry_name($industry_name) {
		$this->industry_name = $industry_name;
		return $this;
	}

	/**
	 * @param field_type $addressline
	 */
	public function setAddressline($addressline) {
		$this->addressline = $addressline;
		return $this;
	}

	/**
	 * @param field_type $city
	 */
	public function setCity($city) {
		$this->city = $city;
		return $this;
	}

	/**
	 * @param field_type $district
	 */
	public function setDistrict($district) {
		$this->district = $district;
		return $this;
	}

	/**
	 * @param field_type $state
	 */
	public function setState($state) {
		$this->state = $state;
		return $this;
	}

	/**
	 * @param field_type $pincode
	 */
	public function setPincode($pincode) {
		$this->pincode = $pincode;
		return $this;
	}
	
	/**
	 * @param field_type $mapper
	 */
	public function setMapper($mapper) {
		$this->mapper = $mapper;
		return $this;
	}
	public function __construct (array $options = null)
    {
        if (is_array($options)) {
            $this->setOptions($options);
            $this->setUser_type_id('RCTR');
        }
        /*
        if (isset($options['agent_reg_id'])) {
            self::isValid();
        }*/
    }
    
    public function __set ($name, $value)
    {
        $method = 'set' . ucfirst($name);
        if ('mapper' == $name || ! method_exists($this, $method)) {
            throw new Exception('Invalid property specified', Zend_Log::DEBUG);
        }
        $this->$method($value);
    }
    
    public function __get ($name)
    {
        $method = 'get' . ucfirst($name);
        if ('mapper' == $name || ! method_exists($this, $method)) {
            throw new Exception('Invalid property specified. :'.$method, Zend_Log::DEBUG);
        }
        return $this->$method();
    }
    
    public function setOptions (array $options)
    {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
        return $this;
    }

	public function register(){
    	
    	$return = $this->getMapper()->register($this);
    	if ($return) {
            if ($return instanceof RP_Model_User_Recruiter) {
            return true;
        	}
        return null;
    	}	
    }
    
    /**
     * (non-PHPdoc)
     * @see RP_Model_User_Base::populateUser()
     * Overridden function from RP_Model_User_Base
     */
 	public function populateUser(){
    	if(parent::populateUser()){
    		return $this->_populateRecruiter();
    	}
    	return false;
    }
    
    protected function _populateRecruiter(){
    	$result = null;
    	$cols = array('recruiter_name','recruiter_type','addressline',
    				  'city','district','state','contact_no','alternate_no','pincode','contact_person');
    	$result = Zend_Db_Table::getDefaultAdapter()
    					->select()
    					->from('recruiter',$cols)
    					->where('user_id = ?',$this->getUser_id())
    					->query()->fetch();
    	Zend_Registry::get('logger')->debug($result);
    	if($result!=null){
    		$this->setRecruiter_name($result['recruiter_name']);
    		$this->setContact_person($result['contact_person']);
    		$this->setContact_no($result['contact_no']);
    		$this->setRecruiter_type($result['recruiter_type']);
    		$this->setAddressline($result['addressline']);
    		$this->setCity($result['city']);
    		$this->setpincode($result['pincode']);
    		$this->setState($result['state']);
    		if(isset($result['district'])){
    			$this->setDistrict($result['district']);
    		}
    		if(isset($result['alternate_no'])){
    			$this->setAlternate_no($result['alternate_no']);
    		}    		
    		return true;
    	}
    	return false;
    }
    
}//End class
?>